/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modulos.paciente.vista;

import basedatos.OperacionesBD;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import modelo.Persona;
import modulos.consulta.oftalmologia.vista.IFrmHCGeneralOftalmologia;
import modulos.consulta.oftalmologia.vista.iFrmListaRecetaOftalmologia;
import modulos.consulta.vista.IFrmHCGeneral;
import modulos.paciente.modelo.Paciente;
import modulos.reservacion.vista.iFrmReservaCita;
import modulos.usuario.modelo.Permiso;
import modulos.usuario.modelo.Usuario;
import vista.frmPrincipal;
import vista.modelo.Mensaje;
import vista.modelo.OperacionesVarias;

/**
 *
 * @author Edulima
 */
public class iFrmLstPaciente extends javax.swing.JInternalFrame {

    private ArrayList<Paciente> listPacientes = new ArrayList<Paciente>();
    public static Paciente mdfPaciente;
    private DefaultTableModel modeloTabla = new DefaultTableModel();
    private int funcion=0;
    public static final int F_RESERVAR_CITA=1;
    
    public iFrmLstPaciente() {
        initComponents();
        OperacionesVarias.cerrarVentanaEscape(this);

        modeloTabla.addColumn("Nro");
        modeloTabla.addColumn("Cedula");
        modeloTabla.addColumn("Apellido");
        modeloTabla.addColumn("Nombre");
        tblPacientes.getColumnModel().getColumn(0).setPreferredWidth(-10);
        tblPacientes.getColumnModel().getColumn(1).setPreferredWidth(60);
        tblPacientes.getColumnModel().getColumn(2).setPreferredWidth(100);
        tblPacientes.getColumnModel().getColumn(3).setPreferredWidth(100);
        tblPacientes.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);

        listPacientes = (ArrayList<Paciente>) OperacionesBD.listar("Paciente");
        txtTotal.setText("" + listPacientes.size());
        listarPacientes();
        
        //Historia Clinica
        Usuario usuario = (Usuario) frmPrincipal.UsuarioLogueado.get(0)[1];
        Permiso permiso = (Permiso) OperacionesBD.buscar("Permiso", "usuario_idPersona", usuario.getIdPersona() + "");
        this.btnHistoriaClinica.setEnabled(permiso.isHistoriaClinica()); 
        
        
        OperacionesVarias.centrar(this);
    }

    public iFrmLstPaciente(int funcion) {
        initComponents();
        OperacionesVarias.cerrarVentanaEscape(this);
        this.funcion=funcion;
        modeloTabla.addColumn("Nro");
        modeloTabla.addColumn("Cedula");
        modeloTabla.addColumn("Apellido");
        modeloTabla.addColumn("Nombre");
        tblPacientes.getColumnModel().getColumn(0).setPreferredWidth(-10);
        tblPacientes.getColumnModel().getColumn(1).setPreferredWidth(60);
        tblPacientes.getColumnModel().getColumn(2).setPreferredWidth(100);
        tblPacientes.getColumnModel().getColumn(3).setPreferredWidth(100);
        tblPacientes.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);

        listPacientes =  (ArrayList<Paciente>) OperacionesBD.listar("Paciente");
        txtTotal.setText("" + listPacientes.size());
        listarPacientes();
        btnEditar.setVisible(false);
        btnNuevoPaciente.setVisible(false);
        btnHistoriaClinica.setVisible(false);
        OperacionesVarias.centrar(this);
        
    }

    private void refrescarTabla() {
        int c = modeloTabla.getRowCount();
        try {
            for (int i = 0; i < c; i++) {
                modeloTabla.removeRow(0);
            }

        } catch (Exception ex) {
            ex.getMessage();
        }

    }

    private void listarPacientes() {
        refrescarTabla();
        int cont = 0;
        for (Paciente pac : listPacientes) {
            cont++;
            Object[] aux1 = {cont,
                pac.getCedula(),
                pac.getApellido(),
                pac.getNombre()
            };
            modeloTabla.addRow(aux1);
        }
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel2 = new javax.swing.JLabel();
        txtBusqueda = new javax.swing.JTextField();
        cmbCriterioBusqueda = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        txtTotal = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        txtDireccion = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        txtTelefono = new javax.swing.JTextField();
        txtMovil = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        txtFNace = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        txtLugarNace = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        txtLugarResi = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        txtRaza = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        txtGrupoS = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        txtSeguro = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        txtEstCivil = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        txtInstruccion = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        txtOcupacion = new javax.swing.JTextField();
        txtProfesion = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        txtCedula = new javax.swing.JTextField();
        txtEdad = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblPacientes = new JTable() {
            public boolean isCellEditable(int rowIndex, int vColIndex) {
                return false;
            }
        };
        btnEditar = new javax.swing.JButton();
        btnHistoriaClinica = new javax.swing.JButton();
        btnCerrar = new javax.swing.JButton();
        btnNuevoPaciente = new javax.swing.JButton();
        btnHistoriaClinica1 = new javax.swing.JButton();
        btnRecetas = new javax.swing.JButton();

        setClosable(true);
        setTitle("PACIENTES");
        setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/jpgs/DoctorMale.png"))); // NOI18N

        jLabel2.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        jLabel2.setText("Buscar:");

        txtBusqueda.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtBusquedaKeyReleased(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtBusquedaKeyTyped(evt);
            }
        });

        cmbCriterioBusqueda.setFont(new java.awt.Font("Times New Roman", 0, 13)); // NOI18N
        cmbCriterioBusqueda.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "C.I.", "Apellido", "Nombre" }));
        cmbCriterioBusqueda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbCriterioBusquedaActionPerformed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        jLabel3.setText("Total:");

        txtTotal.setBackground(new java.awt.Color(250, 249, 203));
        txtTotal.setEditable(false);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED), "Datos Personales", javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.TOP, new java.awt.Font("Dialog", 1, 12), java.awt.SystemColor.activeCaption)); // NOI18N

        jLabel5.setFont(new java.awt.Font("Ubuntu", 1, 14)); // NOI18N
        jLabel5.setText("Direccion:");

        txtDireccion.setBackground(new java.awt.Color(225, 228, 248));
        txtDireccion.setEditable(false);

        jLabel6.setFont(new java.awt.Font("Ubuntu", 1, 14)); // NOI18N
        jLabel6.setText("Telefono:");

        jLabel7.setFont(new java.awt.Font("Ubuntu", 1, 14)); // NOI18N
        jLabel7.setText("Movil:");

        txtTelefono.setBackground(new java.awt.Color(225, 228, 248));
        txtTelefono.setEditable(false);

        txtMovil.setBackground(new java.awt.Color(225, 228, 248));
        txtMovil.setEditable(false);

        jLabel8.setFont(new java.awt.Font("Ubuntu", 1, 14)); // NOI18N
        jLabel8.setText("F Nac:");

        txtFNace.setBackground(new java.awt.Color(225, 228, 248));
        txtFNace.setEditable(false);

        jLabel9.setFont(new java.awt.Font("Ubuntu", 1, 14)); // NOI18N
        jLabel9.setText("Edad:");

        jLabel10.setFont(new java.awt.Font("Ubuntu", 1, 14)); // NOI18N
        jLabel10.setText("L Nac:");

        txtLugarNace.setBackground(new java.awt.Color(225, 228, 248));
        txtLugarNace.setEditable(false);

        jLabel11.setFont(new java.awt.Font("Ubuntu", 1, 14)); // NOI18N
        jLabel11.setText("L Residencia:");

        txtLugarResi.setBackground(new java.awt.Color(225, 228, 248));
        txtLugarResi.setEditable(false);

        jLabel12.setFont(new java.awt.Font("Ubuntu", 1, 14)); // NOI18N
        jLabel12.setText("Raza:");

        txtRaza.setBackground(new java.awt.Color(225, 228, 248));
        txtRaza.setEditable(false);

        jLabel13.setFont(new java.awt.Font("Ubuntu", 1, 14)); // NOI18N
        jLabel13.setText("Grupo S:");

        txtGrupoS.setBackground(new java.awt.Color(225, 228, 248));
        txtGrupoS.setEditable(false);

        jLabel14.setFont(new java.awt.Font("Ubuntu", 1, 14)); // NOI18N
        jLabel14.setText("Seguro:");

        txtSeguro.setBackground(new java.awt.Color(225, 228, 248));
        txtSeguro.setEditable(false);

        jLabel15.setFont(new java.awt.Font("Ubuntu", 1, 14)); // NOI18N
        jLabel15.setText("Estado Civil:");

        txtEstCivil.setBackground(new java.awt.Color(225, 228, 248));
        txtEstCivil.setEditable(false);

        jLabel16.setFont(new java.awt.Font("Ubuntu", 1, 14)); // NOI18N
        jLabel16.setText("Instruccion:");

        txtInstruccion.setBackground(new java.awt.Color(225, 228, 248));
        txtInstruccion.setEditable(false);

        jLabel17.setFont(new java.awt.Font("Ubuntu", 1, 14)); // NOI18N
        jLabel17.setText("Profesion:");

        jLabel18.setFont(new java.awt.Font("Ubuntu", 1, 14)); // NOI18N
        jLabel18.setText("Ocupacion:");

        txtOcupacion.setBackground(new java.awt.Color(225, 228, 248));
        txtOcupacion.setEditable(false);

        txtProfesion.setBackground(new java.awt.Color(225, 228, 248));
        txtProfesion.setEditable(false);

        jLabel19.setFont(new java.awt.Font("Ubuntu", 1, 14)); // NOI18N
        jLabel19.setText("C.I:");

        txtCedula.setBackground(new java.awt.Color(225, 228, 248));
        txtCedula.setEditable(false);

        txtEdad.setBackground(new java.awt.Color(225, 228, 248));
        txtEdad.setEditable(false);
        txtEdad.setFont(new java.awt.Font("Ubuntu", 0, 8)); // NOI18N

        tblPacientes.setBackground(new java.awt.Color(209, 230, 239));
        tblPacientes.setModel(modeloTabla);
        tblPacientes.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblPacientesMouseClicked(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                tblPacientesMouseReleased(evt);
            }
        });
        jScrollPane1.setViewportView(tblPacientes);

        btnEditar.setFont(new java.awt.Font("DejaVu Sans", 0, 12)); // NOI18N
        btnEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jpgs/Edit.png"))); // NOI18N
        btnEditar.setText("Editar Datos Personales");
        btnEditar.setToolTipText("Edite la Informacion ");
        btnEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 413, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel10)
                                    .addComponent(jLabel13)
                                    .addComponent(jLabel15)
                                    .addComponent(jLabel8)
                                    .addComponent(jLabel5)
                                    .addComponent(jLabel19)
                                    .addComponent(jLabel16))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(txtLugarNace, javax.swing.GroupLayout.DEFAULT_SIZE, 137, Short.MAX_VALUE)
                                        .addComponent(txtEstCivil))
                                    .addComponent(txtGrupoS, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(txtCedula, javax.swing.GroupLayout.DEFAULT_SIZE, 137, Short.MAX_VALUE)
                                        .addComponent(txtFNace))
                                    .addComponent(txtInstruccion, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel18)
                                    .addComponent(jLabel14)
                                    .addComponent(jLabel11)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGap(1, 1, 1)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel9)
                                            .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jLabel17, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(txtEdad)
                                        .addComponent(txtRaza, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(txtLugarResi, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(txtSeguro, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(txtOcupacion)
                                        .addComponent(txtProfesion, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE))))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(31, 31, 31)
                                .addComponent(jLabel7)
                                .addGap(51, 51, 51)
                                .addComponent(txtMovil))
                            .addComponent(txtDireccion))
                        .addGap(8, 8, 8))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(btnEditar)
                        .addGap(145, 145, 145))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtCedula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel19)
                    .addComponent(jLabel9)
                    .addComponent(txtEdad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(7, 7, 7)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(txtFNace, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12)
                    .addComponent(txtRaza, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtLugarNace, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10)
                    .addComponent(jLabel11)
                    .addComponent(txtLugarResi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(txtGrupoS, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14)
                    .addComponent(txtSeguro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(txtEstCivil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel18)
                    .addComponent(txtOcupacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtInstruccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel16)
                    .addComponent(jLabel17)
                    .addComponent(txtProfesion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(txtTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtMovil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addGap(29, 29, 29)
                .addComponent(btnEditar)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 411, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        btnHistoriaClinica.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jpgs/PatientData.png"))); // NOI18N
        btnHistoriaClinica.setText("Historia Clinica");
        btnHistoriaClinica.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnHistoriaClinicaActionPerformed(evt);
            }
        });

        btnCerrar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jpgs/agt_home.png"))); // NOI18N
        btnCerrar.setText("Cerrar");
        btnCerrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCerrarActionPerformed(evt);
            }
        });

        btnNuevoPaciente.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jpgs/PatientMale.png"))); // NOI18N
        btnNuevoPaciente.setText("Nuevo Paciente");
        btnNuevoPaciente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNuevoPacienteActionPerformed(evt);
            }
        });

        btnHistoriaClinica1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jpgs/eye.png"))); // NOI18N
        btnHistoriaClinica1.setText("Oftalmologia");
        btnHistoriaClinica1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnHistoriaClinica1ActionPerformed(evt);
            }
        });

        btnRecetas.setText("Recetas Lentes");
        btnRecetas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRecetasActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 9, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cmbCriterioBusqueda, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(txtBusqueda, javax.swing.GroupLayout.PREFERRED_SIZE, 226, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel3)
                                .addGap(6, 6, 6)
                                .addComponent(txtTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addComponent(btnRecetas, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(btnHistoriaClinica1, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(btnHistoriaClinica, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(btnNuevoPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(btnCerrar, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(txtBusqueda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(cmbCriterioBusqueda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel3)
                        .addComponent(txtTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(btnCerrar, javax.swing.GroupLayout.DEFAULT_SIZE, 45, Short.MAX_VALUE)
                        .addComponent(btnHistoriaClinica, javax.swing.GroupLayout.DEFAULT_SIZE, 45, Short.MAX_VALUE)
                        .addComponent(btnNuevoPaciente, javax.swing.GroupLayout.DEFAULT_SIZE, 45, Short.MAX_VALUE)
                        .addComponent(btnHistoriaClinica1, javax.swing.GroupLayout.DEFAULT_SIZE, 45, Short.MAX_VALUE))
                    .addComponent(btnRecetas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(30, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtBusquedaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtBusquedaKeyReleased
        if (cmbCriterioBusqueda.getSelectedItem().toString().trim().equals("C.I.")) {
            listPacientes = (ArrayList<Paciente>) OperacionesBD.listarPrediccion("Paciente", "Cedula", txtBusqueda.getText().trim());
        } else if (cmbCriterioBusqueda.getSelectedItem().toString().trim().equals("Apellido")) {
            listPacientes = (ArrayList<Paciente>) OperacionesBD.listarPrediccion("Paciente", "Apellido", txtBusqueda.getText().trim());
        } else {
            listPacientes = (ArrayList<Paciente>) OperacionesBD.listarPrediccion("Paciente", "Nombre", txtBusqueda.getText().trim());
        }
        listarPacientes();
        limpiarCampos();
    }//GEN-LAST:event_txtBusquedaKeyReleased

    private void tblPacientesMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblPacientesMouseReleased
        if (listPacientes.size() > 0) {
            int aux = tblPacientes.getSelectedRow();
            if (aux != -1) {
                mdfPaciente = listPacientes.get(aux);
                setPaciente();
            }
        }
    }//GEN-LAST:event_tblPacientesMouseReleased

    private void btnCerrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCerrarActionPerformed
        this.dispose();
    }//GEN-LAST:event_btnCerrarActionPerformed

    private void btnEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditarActionPerformed
        if (tblPacientes.getRowCount() > 0) {
            int aux = tblPacientes.getSelectedRow();
            if (aux != -1) {
                mdfPaciente = listPacientes.get(aux);
                iFrmPaciente ifmPaciente = new iFrmPaciente(mdfPaciente);
                frmPrincipal.dskpPrincipal.add(ifmPaciente);
                ifmPaciente.setVisible(true);
                ifmPaciente.toFront();
            } else {
                JOptionPane.showMessageDialog(this, "Seleccione el Paciente que desea editar ...", "Editar Paciente", JOptionPane.WARNING_MESSAGE);
            }
        } else {
            JOptionPane.showMessageDialog(this, "No ha registrado ningun Paciente para poder editar ...", "Editar Paciente", JOptionPane.WARNING_MESSAGE);
        }
    }//GEN-LAST:event_btnEditarActionPerformed

    private void txtBusquedaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtBusquedaKeyTyped
        if (cmbCriterioBusqueda.getSelectedIndex()==0) {
            OperacionesVarias.ingresoNumCedula(evt, txtBusqueda.getText().trim());
        } else {
            OperacionesVarias.ingresoSoloLetras(evt);
        }
    }//GEN-LAST:event_txtBusquedaKeyTyped

    private void cmbCriterioBusquedaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbCriterioBusquedaActionPerformed
        txtBusqueda.setText("");
    }//GEN-LAST:event_cmbCriterioBusquedaActionPerformed

    private void btnHistoriaClinicaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnHistoriaClinicaActionPerformed

        if (tblPacientes.getRowCount() > 0) {
            int aux = tblPacientes.getSelectedRow();
            if (aux != -1) {
                IFrmHCGeneral hCGeneral = new IFrmHCGeneral(mdfPaciente);
                frmPrincipal.dskpPrincipal.add(hCGeneral);
                hCGeneral.toFront();
                hCGeneral.setVisible(true);

            } else {
                JOptionPane.showMessageDialog(this, "Seleccione el Paciente ...", "", JOptionPane.WARNING_MESSAGE);
            }
        } else {
            JOptionPane.showMessageDialog(this, "No ha registrado ningun Paciente ...", "", JOptionPane.WARNING_MESSAGE);
        }


    }//GEN-LAST:event_btnHistoriaClinicaActionPerformed

    private void btnNuevoPacienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNuevoPacienteActionPerformed
        iFrmPaciente frmPaciente = new iFrmPaciente();
        frmPrincipal.dskpPrincipal.add(frmPaciente);
        OperacionesVarias.centrar(frmPaciente);
    }//GEN-LAST:event_btnNuevoPacienteActionPerformed

    private void tblPacientesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblPacientesMouseClicked
            if(funcion==F_RESERVAR_CITA){
                if(evt.getClickCount()==2){
                    int index=tblPacientes.getSelectedRow();
                    if(index!=-1){
                        iFrmReservaCita.setPaciente(mdfPaciente);
                        dispose();
                    }
                }
            }
    }//GEN-LAST:event_tblPacientesMouseClicked

    private void btnHistoriaClinica1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnHistoriaClinica1ActionPerformed
      
        if (tblPacientes.getRowCount() > 0) {
            int aux = tblPacientes.getSelectedRow();
            if (aux != -1) {
                IFrmHCGeneralOftalmologia hCGeneral = new IFrmHCGeneralOftalmologia(mdfPaciente);
                frmPrincipal.dskpPrincipal.add(hCGeneral);
                hCGeneral.toFront();
                hCGeneral.setVisible(true);

            } else {
                JOptionPane.showMessageDialog(this, "Seleccione el Paciente ...", "", JOptionPane.WARNING_MESSAGE);
            }
        } else {
            JOptionPane.showMessageDialog(this, "No ha registrado ningun Paciente ...", "", JOptionPane.WARNING_MESSAGE);
        }


    }//GEN-LAST:event_btnHistoriaClinica1ActionPerformed

    private void btnRecetasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRecetasActionPerformed
       if(tblPacientes.getSelectedRow()!=-1){        
        iFrmListaRecetaOftalmologia lro = new iFrmListaRecetaOftalmologia(mdfPaciente);
        frmPrincipal.dskpPrincipal.add(lro);
        lro.toFront();
        lro.setVisible(true);
       }else{
           Mensaje.filaNoSeleccionada("Paciente");
       }
    }//GEN-LAST:event_btnRecetasActionPerformed

    public static void setPaciente() {

        txtCedula.setText(mdfPaciente.getCedula());
        txtDireccion.setText(mdfPaciente.getDireccion());
        txtEstCivil.setText(mdfPaciente.geteCivil());
        SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
        txtFNace.setText(df.format(mdfPaciente.getFechaNace()));
        txtGrupoS.setText(mdfPaciente.gettSangre());
        txtEdad.setText(Persona.calcularEdad(mdfPaciente.getFechaNace()));
        txtInstruccion.setText(mdfPaciente.getInstruccion());
        txtLugarNace.setText(mdfPaciente.getLugarNace());
        txtLugarResi.setText(mdfPaciente.getLugarResi());
        txtMovil.setText(mdfPaciente.getCelular());
        txtOcupacion.setText(mdfPaciente.getOcupacion());
        txtProfesion.setText(mdfPaciente.getProfeccion());
        txtRaza.setText(mdfPaciente.getRaza());
        txtSeguro.setText(mdfPaciente.getSeguro());
        txtTelefono.setText(mdfPaciente.getTelefono());

    }

    public static void limpiarCampos() {

        txtCedula.setText("");
        txtDireccion.setText("");
        txtEstCivil.setText("");
        txtFNace.setText("");
        txtGrupoS.setText("");
        txtEdad.setText("");
        txtInstruccion.setText("");
        txtLugarNace.setText("");
        txtLugarResi.setText("");
        txtMovil.setText("");
        txtOcupacion.setText("");
        txtProfesion.setText("");
        txtRaza.setText("");
        txtSeguro.setText("");
        txtTelefono.setText("");

    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCerrar;
    private javax.swing.JButton btnEditar;
    private javax.swing.JButton btnHistoriaClinica;
    private javax.swing.JButton btnHistoriaClinica1;
    private javax.swing.JButton btnNuevoPaciente;
    private javax.swing.JButton btnRecetas;
    private javax.swing.JComboBox cmbCriterioBusqueda;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tblPacientes;
    private javax.swing.JTextField txtBusqueda;
    private static javax.swing.JTextField txtCedula;
    private static javax.swing.JTextField txtDireccion;
    private static javax.swing.JTextField txtEdad;
    private static javax.swing.JTextField txtEstCivil;
    private static javax.swing.JTextField txtFNace;
    private static javax.swing.JTextField txtGrupoS;
    private static javax.swing.JTextField txtInstruccion;
    private static javax.swing.JTextField txtLugarNace;
    private static javax.swing.JTextField txtLugarResi;
    private static javax.swing.JTextField txtMovil;
    private static javax.swing.JTextField txtOcupacion;
    private static javax.swing.JTextField txtProfesion;
    private static javax.swing.JTextField txtRaza;
    private static javax.swing.JTextField txtSeguro;
    private static javax.swing.JTextField txtTelefono;
    private javax.swing.JTextField txtTotal;
    // End of variables declaration//GEN-END:variables
}
